﻿using MeterialManager.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MeterialManager.Model
{
    public class MeterialCategory
    {
        public int Id { get; set; }
        public int CategoryId { get; set; }
        public string CategoryName { get; set; }
        public string MeterialCode { get; set; }
        public string MeterialName { get; set; }
        public string Unit { get; set; }
        public int Stocks { get; set; }
        public string Remark { get; set; }


        
        public static List<MeterialCategory> ListAll()
        {
            List<MeterialCategory> meterialCategories = new List<MeterialCategory>();
            DataTable dt = SqlHelper.ExecuteTable("SELECT m.Id,c.CategoryId,c.CategoryName,m.MeterialCode,m.MeterialName,m.Unit,m.Stocks,m.Remark FROM Meterials m LEFT JOIN Categorys c on m.CategoryCode = c.CategoryCode");
            foreach (DataRow dr in dt.Rows)
            {
                meterialCategories.Add(dr.DataRowToModel<MeterialCategory>());
            }
            return meterialCategories;
        }
    }
}
